<?php
include "../include/global.php";
include "../include/admin_check.php";
$xtpl = new XTemplate ("cityWrite.htm");
include "../include/setting.php";
include "setting.php";
include "../include/function.php";


$city_name=$_POST['city_name'];
$city_position=$_POST['city_position'];
$city_isactive=$_POST['city_isactive'];

$ID=_POST('ID');
$type=$_POST['type'];

//
$date = date("Y-m-d");
$sub_mit = $_POST['sub_mit'];
if($sub_mit=="yes"){
	if($city_name==""){
		$error_city_name ="Bạn phải nhập Tên <br />";
	}
	if(!is_numeric_str($city_position)){
		$error_city_position ="Vị trí phải là số <br />";
	}
	$str_error=$error_city_name.$error_city_position;
	if($str_error==""){
		if($type=="ADD"){	
			//
			$sql="INSERT INTO city(city_name, city_position, city_isactive) 
					VALUES	('".$city_name."', '".$city_position."', '".$city_isactive."')";
			execSQL($sql);
		}else{
			$sql="UPDATE city SET 
						city_name='".$city_name."', 
						city_position='".$city_position."', 
						city_isactive='".$city_isactive."'
						WHERE city_id='".$ID."'";			
			execSQL($sql);
		}			

		$act = $_POST['act'];
		if($act=='save'){
			echo '<script>
				parent.document.frmData.target = "_parent";				
				parent.window.location.href="city.php";
			</script>';
		}else{	
			echo '<script>
				parent.document.frmData.target = "_parent";	
				parent.document.frmData.city_name.focus();			
				parent.window.location.href="cityWrite.php";
			</script>';
		}	
		
	}else{
		echo '<script>
				parent.document.frmData.target = "_parent";		
				parent.document.getElementById("err").style.display="block";
				parent.document.getElementById("err_string").innerHTML="'.$str_error.'";
			</script>';	
	}
}
?>